#used for interactive shells
use="all"
confpath=~/.conf/zsh/

#Set some useful variables
HOST="$(hostname)"
HOST="${HOST%%.*}"

source $confpath/inSSH.func
source $confpath/exists.func
source $confpath/set-options.zsh
source $confpath/env.sh
source $confpath/aliases.sh
source $confpath/zsh.load.zsh
source $confpath/zsh.alias.zsh
source $confpath/zsh.complete.zsh
source $confpath/ps1.zsh
source $confpath/home-end.zsh
source $confpath/eval_spin.func
source $confpath/portsnap.zfunc
#source $confpath/start-tmux.sh

#To discover what keycode is being sent, hit ^v
#and then the key you want to test.

# title/precmd/postcmd
function precmd() {
	setCurrentPS1
	title "zsh - $PWD"
}

function preexec() {
  # The full command line comes in as "$1"
  local cmd="$1"
  local -a args

  # add '--' in case $1 is only one word to work around a bug in ${(z)foo}
  # in zsh 4.3.9.
  tmpcmd="$1 --"
  args=${(z)tmpcmd}

  # remove the '--' we added as a bug workaround..
  # per zsh manpages, removing an element means assigning ()
  args[${#args}]=()
  if [ "${args[1]}" = "fg" ] ; then
    local jobnum="${args[2]}"
    if [ -z "$jobnum" ] ; then
      # If no jobnum specified, find the current job.
      for i in ${(k)jobtexts}; do
        [ -z "${jobstates[$i]%%*:+:*}" ] && jobnum=$i
      done
    fi
    cmd="${jobtexts[${jobnum#%}]}"
  else
  fi
  title "$cmd"
}
function title() {
  # This is madness.
  # We replace literal '%' with '%%'
  # Also use ${(V) ...} to make nonvisible chars printable (think cat -v)
  # Replace newlines with '; '
  local value="${${${(V)1//\%/\%\%}//'\n'/; }//'\t'/ }"
  local location

  location="$HOST"
  [ "$USERNAME" != "$LOGNAME" ] && location="${USERNAME}@${location}"

  # Special format for use with print -Pn
  value="%70>...>$value%<<"
  unset PROMPT_SUBST
  case $TERM in
    screen)
      # Put this in your .screenrc:
      # hardstatus string "[%n] %h - %t"
      # termcapinfo xterm 'hs:ts=\E]2;:fs=\007:ds=\E]2;screen (not title yet)\007'
      print -Pn "\ek${value}\e\\"     # screen title (in windowlist)
      print -Pn "\e_${location}\e\\"  # screen location
      ;;
    xterm*)
      print -Pn "\e]0;$value\a"
      ;;
    Eterm*)
		print -Pn "\e]2;$value\a\e[1;\a";;
  esac
  setopt LOCAL_OPTIONS
}


return 0;